package com.example.administrator.xtu_community.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.administrator.xtu_community.R;

import java.util.ArrayList;
import java.util.List;

import com.example.administrator.xtu_community.bean.Comment;
import com.example.administrator.xtu_community.simpleClass.Comments;

public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<CommentsRecyclerViewAdapter.ViewHolder> {

    private Context mContext;

    private final List<Comment> commentsList = new ArrayList<>();

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView userName;
        TextView content;

        public ViewHolder(View view) {
            super(view);
            userName = view.findViewById(R.id.user_name);
            content = view.findViewById(R.id.content);
        }

    }
    public CommentsRecyclerViewAdapter(List<Comment> commentsList) {
        this.commentsList.clear();
        this.commentsList.addAll(commentsList);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.recycler_view_comments,
                parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Comment comment = commentsList.get(position);
        holder.userName.setText("默认用户");
        holder.content.setText(comment.getContent());
    }

    @Override
    public int getItemCount() {
        return commentsList.size();
    }
    public void refresh(List<Comment> list){
        commentsList.clear();
        commentsList.addAll(list);
        notifyDataSetChanged();
    }
}
